package com.example.fraction.slice;

import com.bumptech.glide.Glide;
import com.example.fraction.ResourceTable;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.*;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;

import java.util.List;

public class item_listcontainer extends BaseItemProvider {
    List<date.ResultDTOX.ResultDTO.ListDTO> list;
    Context context;

    public item_listcontainer(List<date.ResultDTOX.ResultDTO.ListDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        Component pare;
        date.ResultDTOX.ResultDTO.ListDTO date=list.get(i);
        if (component!=null){
            pare=component;
        }else {
            pare= LayoutScatter.getInstance(context).parse(ResourceTable.Layout_item,null,false);
        }
        Text text= (Text) pare.findComponentById(ResourceTable.Id_text);
        Image image= (Image) pare.findComponentById(ResourceTable.Id_image);
        Glide.with(context).load(list.get(i).pic).into(image);
        text.setText(date.title);
        pare.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
//                Intent intent=new Intent();
//                Operation operation=new Intent.OperationBuilder()
//                        .withBundleName("com.example.fraction")
//                        .withAbilityName("com.example.fraction.intent_main")
//                        .build();
//                intent.setOperation(operation);
//                intent.setParam("name",list.get(i).url);
//                context.startAbility(intent,1);
                new ToastDialog(context).setText("123").show();
            }
        });
        return pare;
    }
}
